<?php
$page = get_query_var('cpage');

global $post,$wp_query;
$comments = get_comments(array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC'));
if ( $comments )
{ 
?>
<div class="comments-box">
	<div class="comments-title">
		<span>
			<?php comments_number('0', '1', '%' );?>条评论
		</span>
		<span>
			<a href="<?php the_permalink() ?>#comment">我要发表评论!</a>
		</span> 
	</div>		
	<ol class="commentlist">
		<?php 
			//wp_list_comments('avatar_size=48&callback=dhchannel_comment&page='. $page . '&per_page=' . get_option('comments_per_page'). '&reverse_top_level=null' ,$comments); 
			wp_list_comments('avatar_size=48&callback=dhchannel_comment&page='. $page, $comments); 
		?>
	</ol> 
</div>   
<?php
}
else
{

}
dh_commentnavi();

function dh_commentnavi()
{
    // 如果用户在后台选择要显示评论分页
    if (get_option('page_comments')) 
	{
        // 获取评论分页的 html
      //$comment_pages = paginate_comments_links('echo=0');
	 	$baseLink = '';  	
		$baseLink = '&base=' . add_query_arg('cpage','%#%');
		$page = get_query_var('cpage');
		$comment_pages=paginate_comments_links('current=' . $page . $baseLink . '&echo=0');
       // 如果评论分页的 html 不为空, 显示导航式分页
       if ($comment_pages)
	   {
	       echo "<div class='page_navi'>";
           echo $comment_pages;
		   echo "</div>";
       }
    }
 }
?>

<?php
/*****************************************************
 函数名称：mytheme_comment 
 函数作用：重写wp_listcomment的输出，在中间加入楼层号
******************************************************/
function dhchannel_comment($comment, $args, $depth)
{
    $GLOBALS['comment'] = $comment;
    //主评论计数器初始化 begin
	global $commentcount;
	if(!$commentcount) { //初始化楼层计数器
		$page = get_query_var('cpage')-1;
		if($page<0)
		{
		  	$page = abs(intval($_GET['page']))-1;
		}
		$cpp=get_option('comments_per_page');//获取每页评论数
		$commentcount = $cpp * $page;
	}
    //主评论计数器初始化 end
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
	<div id="comment-<?php comment_ID(); ?>"  class="comment-body">
		<div class="comment-author vcard">
		<?php echo get_avatar($comment,$size='48',$default='<path_to_url>' ); ?>
		<?php comment_g_title($comment->comment_author_email); ?>
		<?php printf('<cite class="fn">%s</cite> <span class="says">说到：</span>', get_comment_author_link()) ?>
		</div>
		<?php if ($comment->comment_approved == '0') : ?>
			<em><?php _e('Your comment is awaiting moderation.') ?></em>
			<br />
		<?php endif; ?>		
		<div class="comment-meta commentmetadata">
			<?php printf('%1$s %2$s', get_comment_date(),  get_comment_time()) ?>
			<?php edit_comment_link('[ 编辑 ]','  ','');
			echo " ";
			if ( is_user_logged_in() ) 
			{
				echo '[ <a href="'.wp_nonce_url(get_bloginfo('url').'/wp-admin/comment.php?action=deletecomment&amp;p='.$comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . '" onclick="return confirm(\'你真的想删除这个评论吗?\')" >删除</a> ]';
			}?>	
		</div>
		<?php comment_text() ?>
		<div class="reply">
			<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
		</div>
		<div class="floor"><!-- 主评论楼层号 -->
			<?php if(!$parent_id = $comment->comment_parent) {printf('%1$s楼', ++$commentcount);} ?><!-- 当前页每个主评论自动+1 -->
		</div>
	</div>
<?php 
}
?>